﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lswweb.IDAL;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Domain
{
    public class LogisticsCompanyServices
    {
        private static ILogisticsCompanyDAL logisticsCompanyDAL = DALFactory.CreateLogisticsCompanyDAL();

        public static LogisticsCompanyInfo FindById(int id)
        {
            if (id <= 0)
                return null;

            return logisticsCompanyDAL.FindById(id);
        }

        public static IList<LogisticsCompanyInfo> FindAll()
        {
            return logisticsCompanyDAL.FindAll();
        }

        public static void Insert(LogisticsCompanyInfo info)
        {
            if (info == null)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            try
            {
                logisticsCompanyDAL.Add(info);
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            }
            catch
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);

            }
        }

        public static void Update(LogisticsCompanyInfo info)
        {
            if (info == null)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            try
            {
                logisticsCompanyDAL.Update(info);
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            }
            catch
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);

            }
        }

        public static void Delete(int id)
        {
            if (id <= 0)
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
                return;
            }

            try
            {
                logisticsCompanyDAL.Delete(id);
                SiteContext.RenderMessage(ExceptionType.HandleSuccess);
            }
            catch
            {
                SiteContext.RenderMessage(ExceptionType.UnknownError);
            }
        }
    }
}
